package com.example.hello;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity2 extends AppCompatActivity implements View.OnClickListener{
    float dollar_rate = 0.35f;
    float euro_rate = 0.28f;
    float won_rate = 501;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        //Button btn1 = (Button)findViewById(R.id.btna);
       // btn1.setOnClickListener((View.OnClickListener) this);
        //Button btn2 = (Button)findViewById(R.id.btnb);
        //btn2.setOnClickListener((View.OnClickListener) this);
      // Button btn3 = (Button)findViewById(R.id.btnc);
       // btn3.setOnClickListener((View.OnClickListener) this);

    }

    @Override
    public void onClick(View v) {
        EditText input = (EditText) findViewById(R.id.input);
        TextView result = (TextView) findViewById(R.id.result);
        String inp = input.getText().toString();//获取用户输入，转成tostring方法
        if (inp.length() > 0) {
        float num = Float.parseFloat(inp);
         float r = 0;

            if (v.getId() == R.id.btna) {
                r = num * dollar_rate;
            } else if (v.getId() == R.id.btnb) {
                r = num * euro_rate;
            } else{
                r = num * won_rate;
            }
           result.setText(String.valueOf(r));

        }else{
            Toast.makeText(this, "请输入金额后再进行转换", Toast.LENGTH_SHORT).show();
        }

    }


}